package com.im.common.utils;


import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.List;

/**
 * @auther Zeng
 * @date 2022/12/17 - 17:50
 * @Version 1.0
 */
@Data
public class R extends HashMap<String,Object> {

    public static R seccess(String msg){
        R r = new R();
        r.put("code",200);
        r.put("msg",msg);
        return r;
    }

    public static R seccess(){
        R r = new R();
        r.put("code",200);
        return r;
    }

    public static R success(){
        R r = new R();
        r.put("code",200);
        return r;
    }

    public static R success(Object data){
        R r = new R();
        r.put("code",200);
        r.put("msg","操作成功");
        r.put("data",data);
        return r;
    }


    public static R seccess(Object data){
        R result = new R();
        result.put("code",200);
        result.put("data",data);
        return result;
    }

    public static R seccess(String msg,Object data){
        R result = new R();
        result.put("code",200);
        result.put("msg",msg);
        result.put("data",data);
        return result;
    }

    public static R faild(String msg){
        R result = new R();
        result.put("code",100);
        result.put("msg",msg);
        return result;
    }

    public static R faild(Integer code,String msg){
        R result = new R();
        result.put("code",code);
        result.put("msg",msg);
        return result;
    }

    public static R out(boolean flag,String msg){
        R result = new R();
        if (flag){
            return result.seccess(msg);
        }
        return result.faild(msg);
    }

    public static R out(boolean flag,String msg,String errMsg){
        R result = new R();
        if (flag){
            return result.seccess(msg);
        }
        return result.faild(errMsg);
    }

    public static R out(boolean flag){
        R result = new R();
        if (flag){
            return result.seccess("操作成功");
        }
        return result.faild("操作失败");
    }

//    public static R out(Integer code ,Object data){
//        R result = new R();
//        result.put("code",100);
//        result.put("data", "null");
//        result.put("msg","抱歉,没有找到相关内容");
//        if (data instanceof List) {
//            List obj = (List) data;
//            if (obj.size() == 0) {
//                return result;
//            }
//        }
//        if (data instanceof Page){
//            Page obj = (Page) data;
//            if (obj.getRecords().size() == 0) {
//               return result;
//            }
//        }
//        if (ObjectUtils.isEmpty(data)) {
//            return result;
//        }
//        result.put("msg","查找成功");
//        result.put("code", code);
//        result.put("data", data);
//        return result;
//    }

//    public static R out(boolean isSuccess){
//        R r = new R();
//        if (isSuccess){
//            r.put("code","200");
//            return r;
//        }
//        r.put("code","100");
//        return r;
//    }


}
